package com.zhs.gccs.utils;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.zhs.gccs.R;
import com.zhs.gccs.model.CheckBoxModel;
import com.zhs.gccs.adapter.MultSelectPopAdapter;
import com.zhs.gccs.adapter.PopAdapter;

import java.util.ArrayList;

public class PopupWindowUtils {
    public static PopupWindow initMultSelectPopupWindow(Context context,
                                                        String title,
                                                        ArrayList<CheckBoxModel> data,
                                                        MultSelectPopAdapter.OnItemClickListener onItemClickListener){
        View view = LayoutInflater.from(context).inflate(R.layout.pop_listview_mult_select, null);
        View ll_view = view.findViewById(R.id.ll_view);
        ll_view.setOnClickListener(new OnNoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {

            }
        });
        TextView tv_title = view.findViewById(R.id.tv_title);
        tv_title.setText(title);
        MultSelectPopAdapter ssqyAdapter = new MultSelectPopAdapter(context, data);
        ListView ssqyListView = (ListView) view.findViewById(R.id.lv_pop);
        ssqyListView.setAdapter(ssqyAdapter);
        if(onItemClickListener!=null)ssqyAdapter.setOnItemClickListener(onItemClickListener);
        PopupWindow  ssqyPop = new PopupWindow(view,
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
        ssqyPop.setOutsideTouchable(true);
        ssqyPop.setBackgroundDrawable(new BitmapDrawable());
        ssqyPop.setFocusable(true);
        ssqyPop.setContentView(view);
        return ssqyPop;
    }

    public static PopupWindow initListPopupWindow(Context context,
                                                  ArrayList<String> data,
                                                  PopAdapter.OnItemClickListener onItemClickListener){
        View view = LayoutInflater.from(context).inflate(R.layout.pop_listview, null);
        PopAdapter ssqyAdapter = new PopAdapter(context, data);
        ListView ssqyListView = (ListView) view.findViewById(R.id.lv_pop);
        ssqyListView.setAdapter(ssqyAdapter);
        if(onItemClickListener!=null)ssqyAdapter.setOnItemClickListener(onItemClickListener);
        PopupWindow  ssqyPop = new PopupWindow(view,
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
        ssqyPop.setOutsideTouchable(true);
        ssqyPop.setBackgroundDrawable(new BitmapDrawable());
        ssqyPop.setFocusable(true);
        ssqyPop.setContentView(view);
        return ssqyPop;
    }

    public static PopupWindow initPopupWindow(Context context,View view){
        PopupWindow  ssqyPop = new PopupWindow(view,
                ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, true);
        ssqyPop.setOutsideTouchable(true);
        ssqyPop.setBackgroundDrawable(new BitmapDrawable());
        ssqyPop.setFocusable(true);
        ssqyPop.setContentView(view);
        return ssqyPop;
    }

    public static PopupWindow initPopupWindow(Context context,int height,View view){
        PopupWindow  ssqyPop = new PopupWindow(view,
                ViewGroup.LayoutParams.WRAP_CONTENT,
                height, true);
        ssqyPop.setOutsideTouchable(true);
        ssqyPop.setBackgroundDrawable(new BitmapDrawable());
        ssqyPop.setFocusable(true);
        ssqyPop.setContentView(view);
        return ssqyPop;
    }
}
